class Dog:
    count = 0  # 这就是类属性，在类内，在方法外，调用时需要加上类名
    def __init__(self, name):
        self.name = name
        Dog.count += 1
        print(f'当前该类下已创建的实例数目为{Dog.count}')


test1 = Dog('大黄')  # 括号内的定义是实例属性
test2 = Dog('小白')
print(test1.name)
print(test2.name)
print(test1.count)
print(test2.count)  # 结果可见结论：实例对象名.类属性 的调用，会先去实例属性中找有没有和类属性名字相同的个体，查出其值并返回
# 也即此时默认将点后面的名字看作是实例对象的属性名称，若无，那就去实例所属的类下找，若还是无，代码报错


import random


class Game:
    top_score = 0
    mvp = ''
    def __init__(self, name):
        self.name = name

    def show_help(self):
        print(f'{self.name}你好，这是游戏的帮助信息')

    def show_top_score(self):
        if Game.top_score == 0:
            print(f'{self.name}你好，当前游戏还没有最高分记录，欢迎你来创造记录！')
        else:
            print(f'{self.name}你好，游戏最高分是{Game.top_score}，创造该记录的玩家是{Game.mvp}')

    def start_game(self):
        current_score = random.randint(10, 100)
        if current_score > Game.top_score:
            Game.top_score = current_score
            Game.mvp = f'{self.name}'
        else:
            pass
        print(f'{self.name}你好，你的得分是{current_score}')


xw = Game('小王')
xl = Game('小李')
xz = Game('小张')
xh = Game('小红')
xw.show_top_score()
xw.start_game()
xw.show_top_score()
xw.start_game()
xw.show_top_score()
xw.show_help()
xl.show_top_score()
xl.start_game()
xl.show_top_score()
xl.start_game()
xl.show_top_score()
xz.show_top_score()
xz.start_game()
xz.show_top_score()
xz.start_game()
xz.show_top_score()
xh.show_top_score()
xh.start_game()
xh.show_top_score()
xh.start_game()
xh.show_top_score()
